package com.cmcc.aregister.ui.dialog;

import java.util.List;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.constant.HelpInc;
import com.cmcc.aregister.cs.model.MastEntity;
import com.cmcc.aregister.cs.model.ScheduleModel;
import com.cmcc.aregister.ui.adapter.ChoiceOtherSchAdapter;
import com.cmcc.aregister.ui.adapter.DocChooseAdapter;

/**
 * 快速预约请求得到医生的排班信息列表
 * @author ld 20130302
 * 
 */
public class QuickYuyueDlg extends Dialog {
    ListView list;
    List<MastEntity> mastList;
    List<ScheduleModel> schList;
    Context context;
    HelpInc inc;
    boolean isOther = false;

    public QuickYuyueDlg(Context context, List<MastEntity> mastList, HelpInc inc) {
        super(context);
        this.mastList = mastList;
        this.context = context;
        this.inc = inc;
    }

    public QuickYuyueDlg(Context context, List<ScheduleModel> schList,
        HelpInc inc, boolean isOther) {
        super(context);
        this.schList = schList;
        this.context = context;
        this.inc = inc;
        this.isOther = isOther;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(context.getString(R.string.choose_mast));
        setContentView(R.layout.quick_yuyue);
        list = (ListView) findViewById(R.id.list);
        list.setOnItemClickListener(mOnItemClickListener);
        if (isOther) {// 快速预约（异地）
            ChoiceOtherSchAdapter mChoiceOtherSchAdapter = new ChoiceOtherSchAdapter(
                context, schList, true, null);
            list.setAdapter(mChoiceOtherSchAdapter);
        }
        else {
            DocChooseAdapter adapter = new DocChooseAdapter(context, mastList);
            list.setAdapter(adapter);
        }
    }

    OnItemClickListener mOnItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view,
            int position, long id) {
            if (isOther) { // 快速预约（异地）
                String content = "";
                String sch_id = "";
                if (position > schList.size() - 1) {
                    content = context.getString(R.string.kefu_sch);
                    sch_id = "0";
                }
                else {
                    content = schList.get(position).healDate + " "
                        + schList.get(position).weekDay + " "
                        + schList.get(position).dayTime;
                    sch_id = schList.get(position).recordId;
                }
                inc.notifyUI_other(sch_id, content);
            }
            else {
                String schedule_id = mastList.get(position).schedule_id;
                inc.notifyUI(schedule_id);
            }
        }
    };

}